package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;

import org.come.Frame.FactionAngelJframe;
import org.come.bean.LoginResult;
import org.come.until.CutButtonImage;
import org.come.until.ScrollUI;
import org.come.until.SrcollPanelUI;

import com.tool.btn.FactionBtn;
import com.tool.btn.FormsOnOffBtn;
import com.tool.role.RoleData;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;

 

/**
 * 帮派守护神
 * 
 * @author HGC<br>
 * @time 2020年1月13日 下午3:35:54<br>
 * @class 类名:FactionAngelJpanel<br>
 */
public class FactionAngelJpanel extends JPanel {

    /**
     * 字段名:btnMenuSmall <br>
     * 字段名:btnMenuBig <br>
     * 字段名:btnPractice <br>
     * 字段名:btnWash <br>
     * 字段名:btnExchange <br>
     * 字段名:btnYes <br>
     */
    private FactionBtn btnMenuSmall, btnMenuBig, btnPractice, btnWash, btnExchange, btnYes;

    private JLabel labLvl;

    private JScrollPane scrollPane;

    private JList<FactionAngelModelJpanel> listFactionJpanel;

    /**
     * 字段名:typeLvl 等级 小成30 大成60<br>
     */
    private int typeLvl = 30;
    /**
     * 字段名:menuType 面板标识 1小成修炼 2大成修炼<br>
     */
    private int menuType = 0;

    /**
     * 字段名:typeLvlNow 修炼总点数<br>
     * 字段名:typeLvlResidue 修炼剩余点数<br>
     */
    private int typeLvlNow = 0, typeLvlResidue;

    public FactionAngelJpanel() {
    		setPreferredSize(new Dimension(382, 397));
            setOpaque(false);
            setLayout(null);

            // 关闭按钮事件
            FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 54);
            offBtn.setBounds(382 - 37, 10, 25, 25);
            this.add(offBtn);

        getBtnMenuBig();
        getBtnMenuSmall();
        getScrollPane();
        getBtnPractice();
        getLabLvl();
        getBtnWash();
        getBtnExchange();
        getBtnYes();
    }

    /** 展示不同修炼的面板数据 */
    public void changeMenuShow(int type) {
    	try {
    			if (menuType!=type) {
    				menuType = type;
    				if (menuType == 1) {
                    	btnMenuSmall.setIcons(CutButtonImage.cuts("skin/8100226/button/B287.png"));
                        btnMenuBig.setIcons(CutButtonImage.cuts("skin/8100226/button/B284.png"));
                        typeLvl = 30;
                    } else if (menuType == 2) {
                    	btnMenuSmall.setIcons(CutButtonImage.cuts("skin/8100226/button/B286.png"));
                        btnMenuBig.setIcons(CutButtonImage.cuts("skin/8100226/button/B285.png"));
                        typeLvl = 60;
                    }
    			}
			showMenuMessage();
		} catch (Exception e) {
			// TODO: handle exception
		}
    }

    /** 展示信息 */
    public void showMenuMessage() {
        LoginResult loginResult = RoleData.getRoleData().getLoginResult();
        typeLvlResidue = 0;
        if (menuType == 1) {
            String[] resistance = loginResult.getResistance("X");
            int extraPointInt = loginResult.getExtraPointInt("X");
            FactionAngelJframe.getFactionAngelJframe().getFactionAngelJpanel().setTypeLvlNow(extraPointInt);
            for (int i = 0; i < 13; i++) {
                int componentCount = listFactionJpanel.getComponentCount();
                if (componentCount >= 13) {
                    FactionAngelModelJpanel factionAngelModelJpanel = (FactionAngelModelJpanel) listFactionJpanel.getComponent(i);
                    factionAngelModelJpanel.showModel(i + 1, resistance, this);
                } else {
                    FactionAngelModelJpanel factionAngelModelJpanel = new FactionAngelModelJpanel();
                    factionAngelModelJpanel.setBounds(0, componentCount * 34, 324, 34);
                    listFactionJpanel.add(factionAngelModelJpanel);
                }
            }
            listFactionJpanel.setPreferredSize(new Dimension(324, 40 * 13));
            typeLvlResidue = extraPointInt - typeLvlResidue;
            labLvl.setText(extraPointInt + "/30");
        } else if (menuType == 2) {
            String[] resistance = loginResult.getResistance("D");
            int extraPointInt = loginResult.getExtraPointInt("D");
            FactionAngelJframe.getFactionAngelJframe().getFactionAngelJpanel().setTypeLvlNow(extraPointInt);
            for (int i = 0; i < 18; i++) {
                int componentCount = listFactionJpanel.getComponentCount();
                if (componentCount >= 18) {
                    FactionAngelModelJpanel factionAngelModelJpanel = (FactionAngelModelJpanel) listFactionJpanel.getComponent(i);
                    factionAngelModelJpanel.showModel(i + 13, resistance, this);
                } else {
                    FactionAngelModelJpanel factionAngelModelJpanel = new FactionAngelModelJpanel();
                    factionAngelModelJpanel.setBounds(0, componentCount * 34, 324, 34);
                    listFactionJpanel.add(factionAngelModelJpanel);
                }
            }
            typeLvlResidue = extraPointInt - typeLvlResidue;
            labLvl.setText(extraPointInt + "/60");
            listFactionJpanel.setPreferredSize(new Dimension(324, 44 * 18));
        }
    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        	if (icon == null) {
                icon = new ImageIcon("inkImg/old/background/S172.png");
            }
            g.drawImage(icon.getImage(), 0, 0, 382, 397, null);
    }

    public FactionBtn getBtnMenuSmall() {
        if (btnMenuSmall == null) {
        		btnMenuSmall = new FactionBtn("skin/8100226/button/B287.png", 1, 16, this);
                btnMenuSmall.setBounds(51, 30, 96, 26);
            this.add(btnMenuSmall);
        }
        return btnMenuSmall;
    }

    public void setBtnMenuSmall(FactionBtn btnMenuSmall) {
        this.btnMenuSmall = btnMenuSmall;
    }

    public FactionBtn getBtnMenuBig() {
        if (btnMenuBig == null) {
        		btnMenuBig = new FactionBtn("skin/8100226/button/B284.png", 1, 17, this);
                btnMenuBig.setBounds(149, 30, 96, 26);
            this.add(btnMenuBig);
        }
        return btnMenuBig;
    }

    public void setBtnMenuBig(FactionBtn btnMenuBig) {
        this.btnMenuBig = btnMenuBig;
    }

    public ImageIcon getIcon() {
        return icon;
    }

    public void setIcon(ImageIcon icon) {
        this.icon = icon;
    }

    public FactionBtn getBtnPractice() {
        if (btnPractice == null) {
        		btnPractice = new FactionBtn("skin/8100226/button/2.png", 1, UIUtils.COLOR_BTNTEXT, "修炼", UIUtils.TEXT_FONT, 20,
                        this);
                btnPractice.setBounds(176, 352, 34, 17);
            this.add(btnPractice);
        }
        return btnPractice;
    }

    public void setBtnPractice(FactionBtn btnPractice) {
        this.btnPractice = btnPractice;
    }

    public FactionBtn getBtnWash() {
        if (btnWash == null) {
        		btnWash = new FactionBtn("skin/8100226/button/2.png", 1, UIUtils.COLOR_BTNTEXT, "洗点", UIUtils.TEXT_FONT, 21, this);
                btnWash.setBounds(216, 352, 34, 17);
            this.add(btnWash);
        }
        return btnWash;
    }

    public void setBtnWash(FactionBtn btnWash) {
        this.btnWash = btnWash;
    }

    public FactionBtn getBtnExchange() {
        if (btnExchange == null) {
        		btnExchange = new FactionBtn("skin/8100226/button/2.png", 1, UIUtils.COLOR_BTNTEXT, "兑换", UIUtils.TEXT_FONT, 22,
                        this);
//                btnExchange.setBounds(252, 352, 34, 17);
            this.add(btnExchange);
        }
        return btnExchange;
    }

    public void setBtnExchange(FactionBtn btnExchange) {
        this.btnExchange = btnExchange;
    }

    public FactionBtn getBtnYes() {
        if (btnYes == null) {
        		btnYes = new FactionBtn("skin/8100226/newbutton/B20.png", 1, UIUtils.COLOR_BLACK, "确定", UIUtils.TEXT_HY16, 23,
                        this);
                btnYes.setBounds(300, 348, 59, 24);
            this.add(btnYes);
        }
        return btnYes;
    }

    public void setBtnYes(FactionBtn btnYes) {
        this.btnYes = btnYes;
    }

    public JLabel getLabLvl() {
        if (labLvl == null) {
            labLvl = new JLabel("0/" + typeLvl);
            labLvl.setOpaque(false);
            labLvl.setBounds(131, 353, 81, 16);
            labLvl.setForeground(Color.white);
            labLvl.setFont(UIUtils.TEXT_FONT1);
            this.add(labLvl);
        }
        return labLvl;
    }

    public void setLabLvl(JLabel labLvl) {
        this.labLvl = labLvl;
    }

    public JScrollPane getScrollPane() {
        if (scrollPane == null) {
            scrollPane = new JScrollPane(getListFactionJpanel());
            scrollPane.setBounds(53, 58, 307, 276);
            scrollPane.setBorder(BorderFactory.createEmptyBorder());
            scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            scrollPane.setOpaque(false);
            scrollPane.getViewport().setOpaque(false);
            scrollPane.getVerticalScrollBar().setUI(new ScrollUI());
            scrollPane.getVerticalScrollBar().setUnitIncrement(30);
            this.add(scrollPane);
        }
        return scrollPane;
    }

    public void setScrollPane(JScrollPane scrollPane) {
        this.scrollPane = scrollPane;
    }

    public JList<FactionAngelModelJpanel> getListFactionJpanel() {
        if (listFactionJpanel == null) {
            listFactionJpanel = new JList<>();
            listFactionJpanel.setOpaque(false);
            listFactionJpanel.removeAll();
            for (int i = 0; i < 18; i++) {
                FactionAngelModelJpanel factionAngelModelJpanel = new FactionAngelModelJpanel();
                factionAngelModelJpanel.setBounds(0, i * 44, 324, 34);
                listFactionJpanel.add(factionAngelModelJpanel);
            }
            listFactionJpanel.setPreferredSize(new Dimension(324, 20 * 34));
        }
        return listFactionJpanel;
    }

    public void setListFactionJpanel(JList<FactionAngelModelJpanel> listFactionJpanel) {
        this.listFactionJpanel = listFactionJpanel;
    }

    public int getTypeLvl() {
        return typeLvl;
    }

    public void setTypeLvl(int typeLvl) {
        this.typeLvl = typeLvl;
    }

    public int getMenuType() {
        return menuType;
    }

    public void setMenuType(int menuType) {
        this.menuType = menuType;
    }

    public int getTypeLvlNow() {
        return typeLvlNow;
    }

    public void setTypeLvlNow(int typeLvlNow) {
        this.typeLvlNow = typeLvlNow;
    }

    public int getTypeLvlResidue() {
        return typeLvlResidue;
    }

    public void setTypeLvlResidue(int typeLvlResidue) {
        this.typeLvlResidue = typeLvlResidue;
    }

}
